<?php

namespace App\Http\Controllers\Supply;

use App\Http\Controllers\Admin\Traits\AdminTrait;
use App\Http\Service\SupplyService;
use App\Http\Requests\Admin\BaseRequest;
use Illuminate\Support\Facades\Log;

class IndexController extends BaseController
{
    use AdminTrait;

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @desc 供应商审核
     */
    public function uptown(BaseRequest $request, SupplyService $supplyService)
    {
        try {
            $result = $supplyService->uptown($request->all());

            return $this->success($result);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getCode(), $e->getMessage()]);
        }
    }

    /**
     * @desc 供应商申请详情
     */
    public function info(BaseRequest $request, SupplyService $supplyService)
    {
        try {
            $result = $supplyService->getDetail($request->all());
            return $this->success($result);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getCode(), $e->getMessage()]);
        }
    }

    /**
     * @desc 供应商列表
     */
    public function list(BaseRequest $request, SupplyService $supplyService)
    {
        try {
            $input = $request->all();
            $this->getPageAndSize($input);

            $result = $supplyService->getList($request->all(), $this->skip, $this->size);
            return $this->success($result);
        } catch (\Exception $e) {
            Log::error($request->route()->uri, ['errMsg' => $e->getMessage(), 'params' => $request->all()]);
            return $this->error([$e->getCode(), $e->getMessage()]);
        }
    }

}
